package com.shujia.flink.sql
import org.apache.flink.streaming.api.scala._
import org.apache.flink.table.api._
import org.apache.flink.table.api.bridge.scala._
import org.apache.flink.types.Row
object Demo7Hbase {
  def main(args: Array[String]): Unit = {

    val bsEnv: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    bsEnv.setParallelism(1)

    val bsSettings: EnvironmentSettings = EnvironmentSettings
      .newInstance()
      .useBlinkPlanner() //指定计划器为blink
      .inStreamingMode() //指定流模式
      .build()
    /**
      *
      * 构建flink table环境
      *
      */
    val bsTableEnv: StreamTableEnvironment = StreamTableEnvironment.create(bsEnv, bsSettings)


    bsTableEnv.executeSql(
      """
        |
        |CREATE TABLE student (
        | id STRING,
        | info ROW<age STRING,gender STRING,clazz STRING,name STRING>,
        |  PRIMARY KEY (id) NOT ENFORCED
        |) WITH (
        | 'connector' = 'hbase-1.4',
        | 'table-name' = 'student',
        | 'zookeeper.quorum' = 'master:2181,node1:2181,node2:2181'
        |)
        |
      """.stripMargin)


    bsTableEnv.sqlQuery(
      """
        |select info.clazz,count(1) from student group by info.clazz
        |
      """.stripMargin).toRetractStream[Row].print()


    bsEnv.execute()
  }
}
